/*
 * Copyright 2021 Shaoguang.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <QApplication>
#include <QWidget>

#include <QTimer>
#include <QDebug>

#include "../TinyScreenRecorder.h"

int main(int argc, char* argv[])
{
    QApplication a(argc, argv);

    TinyScreenRecorder screenRecorder;
    screenRecorder.setVideoFileName("screen-record-10s.avi");
    screenRecorder.start();
    // recording 10 seconds
    QTimer::singleShot(10 * 1000, &screenRecorder, &TinyScreenRecorder::stop);

    QObject::connect(&screenRecorder, &TinyScreenRecorder::recordingStarted, &a, [](){
        qDebug() << "recording started";
    });
    QObject::connect(&screenRecorder, &TinyScreenRecorder::fpsDetected, &a, [](double fps){
        qDebug() << "fps detected: " << fps;
    });
    QObject::connect(&screenRecorder, &TinyScreenRecorder::frameRecorded, &a, [](qint64 fc){
        qDebug() << "frame recorded: " << fc;
    });
    QObject::connect(&screenRecorder, &TinyScreenRecorder::frameMissed, &a, [](qint64 fc){
        qDebug() << "frame missed: " << fc;
    });
    QObject::connect(&screenRecorder, &TinyScreenRecorder::recordingFinished, &a, [&a](){
        qDebug() << "recording finished";
        a.quit();
    });
    QObject::connect(&screenRecorder, &TinyScreenRecorder::errorOccurred, &a, [](const QString& error){
        qDebug() << "error: " << error;
    });


    return a.exec();
}